/**
 * @brief  Common enums wrapper of cuSolver
 *
 */

#ifndef CUSOLVER_COMMON_WRAPPER_H
#define CUSOLVER_COMMON_WRAPPER_H

#include "mcsolver_common.h"

#ifndef ENABLE_CUDA_TO_MACA_ADAPTOR
#define ENABLE_CUDA_TO_MACA_ADAPTOR
#endif

#define CUSOLVER_COMMON_H_ MCSOLVER_CUSOLVER_COMMON_H_

#ifndef CUSOLVERAPI
#ifdef _WIN32
#define CUSOLVERAPI __stdcall
#else
#define CUSOLVERAPI
#endif
#endif

#if defined(_MSC_VER)
typedef __int64 int64_t;
#else
#include <inttypes.h>
#endif

#define cusolver_int_t mcblas_int

#define CUSOLVER_VER_MAJOR 11
#define CUSOLVER_VER_MINOR 3
#define CUSOLVER_VER_PATCH 0
#define CUSOLVER_VER_BUILD 0
#define CUSOLVER_VERSION (CUSOLVER_VER_MAJOR * 1000 + CUSOLVER_VER_MINOR * 100 + CUSOLVER_VER_PATCH)

/*
 * disable this macro to proceed old API
 */
#define DISABLE_CUSOLVER_DEPRECATED DISABLE_MCSOLVER_DEPRECATED

//------------------------------------------------------------------------------

#if !defined(_MSC_VER)
#define CUSOLVER_CPP_VERSION __cplusplus
#elif _MSC_FULL_VER >= 190024210  // Visual Studio 2015 Update 3
#define CUSOLVER_CPP_VERSION _MSVC_LANG
#else
#define CUSOLVER_CPP_VERSION 0
#endif

//------------------------------------------------------------------------------

#if !defined(DISABLE_CUSOLVER_DEPRECATED)

#if CUSOLVER_CPP_VERSION >= 201402L

#define CUSOLVER_DEPRECATED(new_func) [[deprecated("please use " #new_func " instead")]]

#elif defined(_MSC_VER)

#define CUSOLVER_DEPRECATED(new_func) __declspec(deprecated("please use " #new_func " instead"))

#elif defined(__INTEL_COMPILER) || defined(__clang__) || \
    (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)))

#define CUSOLVER_DEPRECATED(new_func) __attribute__((deprecated("please use " #new_func " instead")))

#elif defined(__GNUC__) || defined(__xlc__)

#define CUSOLVER_DEPRECATED(new_func) __attribute__((deprecated))

#else

#define CUSOLVER_DEPRECATED(new_func)

#endif  // defined(__cplusplus) && __cplusplus >= 201402L
//------------------------------------------------------------------------------

#if CUSOLVER_CPP_VERSION >= 201703L

#define CUSOLVER_DEPRECATED_ENUM(new_enum) [[deprecated("please use " #new_enum " instead")]]

#elif defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 6 && !defined(__PGI))

#define CUSOLVER_DEPRECATED_ENUM(new_enum) __attribute__((deprecated("please use " #new_enum " instead")))

#else

#define CUSOLVER_DEPRECATED_ENUM(new_enum)

#endif  // defined(__cplusplus) && __cplusplus >= 201402L

#else  // defined(DISABLE_CUSOLVER_DEPRECATED)

#define CUSOLVER_DEPRECATED(new_func)
#define CUSOLVER_DEPRECATED_ENUM(new_enum)

#endif  // !defined(DISABLE_CUSOLVER_DEPRECATED)

#undef CUSOLVER_CPP_VERSION

// cusolverStatus_t
#define cusolverStatus_t mcsolverStatus_t
#define CUSOLVER_STATUS_SUCCESS MCSOLVER_STATUS_SUCCESS
#define CUSOLVER_STATUS_NOT_INITIALIZED MCSOLVER_STATUS_NOT_INITIALIZED
#define CUSOLVER_STATUS_ALLOC_FAILED MCSOLVER_STATUS_ALLOC_FAILED
#define CUSOLVER_STATUS_INVALID_VALUE MCSOLVER_STATUS_INVALID_VALUE
#define CUSOLVER_STATUS_ARCH_MISMATCH MCSOLVER_STATUS_ARCH_MISMATCH
#define CUSOLVER_STATUS_MAPPING_ERROR MCSOLVER_STATUS_MAPPING_ERROR
#define CUSOLVER_STATUS_EXECUTION_FAILED MCSOLVER_STATUS_EXECUTION_FAILED
#define CUSOLVER_STATUS_INTERNAL_ERROR MCSOLVER_STATUS_INTERNAL_ERROR
#define CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED MCSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED
#define CUSOLVER_STATUS_NOT_SUPPORTED MCSOLVER_STATUS_NOT_SUPPORTED
#define CUSOLVER_STATUS_ZERO_PIVOT MCSOLVER_STATUS_ZERO_PIVOT
#define CUSOLVER_STATUS_INVALID_LICENSE MCSOLVER_STATUS_INVALID_LICENSE
#define CUSOLVER_STATUS_IRS_PARAMS_NOT_INITIALIZED MCSOLVER_STATUS_IRS_PARAMS_NOT_INITIALIZED
#define CUSOLVER_STATUS_IRS_PARAMS_INVALID MCSOLVER_STATUS_IRS_PARAMS_INVALID
#define CUSOLVER_STATUS_IRS_PARAMS_INVALID_PREC MCSOLVER_STATUS_IRS_PARAMS_INVALID_PREC
#define CUSOLVER_STATUS_IRS_PARAMS_INVALID_REFINE MCSOLVER_STATUS_IRS_PARAMS_INVALID_REFINE
#define CUSOLVER_STATUS_IRS_PARAMS_INVALID_MAXITER MCSOLVER_STATUS_IRS_PARAMS_INVALID_MAXITER
#define CUSOLVER_STATUS_IRS_INTERNAL_ERROR MCSOLVER_STATUS_IRS_INTERNAL_ERROR
#define CUSOLVER_STATUS_IRS_NOT_SUPPORTED MCSOLVER_STATUS_IRS_NOT_SUPPORTED
#define CUSOLVER_STATUS_IRS_OUT_OF_RANGE MCSOLVER_STATUS_IRS_OUT_OF_RANGE
#define CUSOLVER_STATUS_IRS_NRHS_NOT_SUPPORTED_FOR_REFINE_GMRES MCSOLVER_STATUS_IRS_NRHS_NOT_SUPPORTED_FOR_REFINE_GMRES
#define CUSOLVER_STATUS_IRS_INFOS_NOT_INITIALIZED MCSOLVER_STATUS_IRS_INFOS_NOT_INITIALIZED
#define CUSOLVER_STATUS_IRS_INFOS_NOT_DESTROYED MCSOLVER_STATUS_IRS_INFOS_NOT_DESTROYED
#define CUSOLVER_STATUS_IRS_MATRIX_SINGULAR MCSOLVER_STATUS_IRS_MATRIX_SINGULAR
#define CUSOLVER_STATUS_INVALID_WORKSPACE MCSOLVER_STATUS_INVALID_WORKSPACE

#define cusolverEigType_t mcsolverEigType_t
#define CUSOLVER_EIG_TYPE_1 MCSOLVER_EIG_TYPE_1
#define CUSOLVER_EIG_TYPE_2 MCSOLVER_EIG_TYPE_2
#define CUSOLVER_EIG_TYPE_3 MCSOLVER_EIG_TYPE_3

#define cusolverEigMode_t mcsolverEigMode_t
#define CUSOLVER_EIG_MODE_NOVECTOR MCSOLVER_EIG_MODE_NOVECTOR
#define CUSOLVER_EIG_MODE_VECTOR MCSOLVER_EIG_MODE_VECTOR

#define cusolverEigRange_t mcsolverEigRange_t
#define CUSOLVER_EIG_RANGE_ALL MCSOLVER_EIG_RANGE_ALL
#define CUSOLVER_EIG_RANGE_I MCSOLVER_EIG_RANGE_I
#define CUSOLVER_EIG_RANGE_V MCSOLVER_EIG_RANGE_V

#define cusolverNorm_t mcsolverNorm_t
#define CUSOLVER_INF_NORM MCSOLVER_INF_NORM
#define CUSOLVER_MAX_NORM MCSOLVER_MAX_NORM
#define CUSOLVER_ONE_NORM MCSOLVER_ONE_NORM
#define CUSOLVER_FRO_NORM MCSOLVER_FRO_NORM

#define cusolverIRSRefinement_t mcsolverIRSRefinement_t
#define CUSOLVER_IRS_REFINE_NOT_SET MCSOLVER_IRS_REFINE_NOT_SET
#define CUSOLVER_IRS_REFINE_NONE MCSOLVER_IRS_REFINE_NONE
#define CUSOLVER_IRS_REFINE_CLASSICAL MCSOLVER_IRS_REFINE_CLASSICAL
#define CUSOLVER_IRS_REFINE_CLASSICAL_GMRES MCSOLVER_IRS_REFINE_CLASSICAL_GMRES
#define CUSOLVER_IRS_REFINE_GMRES MCSOLVER_IRS_REFINE_GMRES
#define CUSOLVER_IRS_REFINE_GMRES_GMRES MCSOLVER_IRS_REFINE_GMRES_GMRES
#define CUSOLVER_IRS_REFINE_GMRES_NOPCOND MCSOLVER_IRS_REFINE_GMRES_NOPCOND
#define CUSOLVER_PREC_DD MCSOLVER_PREC_DD
#define CUSOLVER_PREC_SS MCSOLVER_PREC_SS
#define CUSOLVER_PREC_SHT MCSOLVER_PREC_SHT

#define cusolverPrecType_t mcsolverPrecType_t
#define CUSOLVER_R_8I MCSOLVER_R_8I
#define CUSOLVER_R_8U MCSOLVER_R_8U
#define CUSOLVER_R_64F MCSOLVER_R_64F
#define CUSOLVER_R_32F MCSOLVER_R_32F
#define CUSOLVER_R_16F MCSOLVER_R_16F
#define CUSOLVER_R_16BF MCSOLVER_R_16BF
#define CUSOLVER_R_TF32 MCSOLVER_R_TF32
#define CUSOLVER_R_AP MCSOLVER_R_AP
#define CUSOLVER_C_8I MCSOLVER_C_8I
#define CUSOLVER_C_8U MCSOLVER_C_8U
#define CUSOLVER_C_64F MCSOLVER_C_64F
#define CUSOLVER_C_32F MCSOLVER_C_32F
#define CUSOLVER_C_16F MCSOLVER_C_16F
#define CUSOLVER_C_16BF MCSOLVER_C_16BF
#define CUSOLVER_C_TF32 MCSOLVER_C_TF32
#define CUSOLVER_C_AP MCSOLVER_C_AP

#define cusolverAlgMode_t mcsolverAlgMode_t
#define CUSOLVER_ALG_0 MCSOLVER_ALG_0
#define CUSOLVER_ALG_1 MCSOLVER_ALG_1
#define CUSOLVER_ALG_2 MCSOLVER_ALG_2

#define cusolverStorevMode_t mcsolverStorevMode_t
#define cusolverDirectMode_t mcsolverDirectMode_t

#define cusolverGetProperty mcsolverGetProperty

#define cusolverGetVersion mcsolverGetVersion

#endif  // CUSOLVER_COMMON_WRAPPER_H_
